<?php
namespace app\decorate\model;
use app\BaseModel;
use think\facade\Db;



class AdminEvaluate extends BaseModel
{
    //定义表名 评论表
    protected $name = 'longbing_card_decorate_evaluate';

    /**
     * @param $query
     * 查询范围
     */
    public function scopeStatus($query, $status){
        $query->where('status', '>', $status);
    }
    /**
     * User: chenniang
     * Date: 2019-10-14 10:39
     * @param $value
     * @return void
     * descption:转换图片
     */
    public function getImgsAttr($value){
        $data = transImages([$value],['imgs']);
        return !empty($data[0])?$data[0]:[];
    }
    /**
     * User: chenniang
     * Date: 2019-10-14 10:39
     * @param $value
     * @return void
     * descption:转换视频
     */
    public function getVideoAttr($value){
        $data = transImagesOne([$value],['video']);
        return !empty($data[0])?$data[0]:[];
    }
    /**
     * @param $dis
     * @return array
     * @throws \think\exception\DbException
     * 评论列表
     */
    public function evaList($dis,$page = 10){
        $data = $this->alias('a')
            ->leftJoin('longbing_card_user b','b.id=a.user_id')
            ->leftJoin('longbing_card_user_info c','c.fans_id=a.staff_id')
            ->where($dis)
            ->status(-1)
            ->field(['a.*','b.nickName','c.name as staff_name'])
            ->group('a.id')
            ->paginate($page)
            ->toArray();
        return $data;
    }
    /**
     * @param $data
     * @return int|string
     * 添加评论
     */
    public function evaAdd($data){
        $data['create_time'] = time();
        $data['update_time'] = time();
        $res = $this->insert($data);
        return $res;
    }
    /**
     * @param $dis
     * @param $data
     * @return AdminCate
     * 编辑评论
     */
    public function evaUpdate($dis,$data){
        $data['update_time'] = time();
        $res = $this->where($dis)->update($data);
        return $res;

    }
    /**
     * @param $dis
     * @return AdminCate
     * 评论详情
     */
    public function evaInfo($dis){
        $data =$this->alias('a')
            ->leftJoin('longbing_card_user b','b.id=a.user_id')
            ->leftJoin('longbing_card_user_info c','c.fans_id=a.staff_id')
            ->where($dis)
            ->status(-1)
            ->field(['a.*','b.nickName','c.name as staff_name'])
            ->find();
        return !empty($data)?$data->toArray():$data;
    }




}